package pl.nazaweb.imedproplus.model.entity;

import pl.nazaweb.imedproplus.model.interfaces.IPatient;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "patient")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Patient.findAll", query = "SELECT p FROM Patient p"),
    @NamedQuery(name = "Patient.findById", query = "SELECT p FROM Patient p WHERE p.id = :id"),
    @NamedQuery(name = "Patient.findByFirstName", query = "SELECT p FROM Patient p WHERE p.firstName = :firstName"),
    @NamedQuery(name = "Patient.findByLastName", query = "SELECT p FROM Patient p WHERE p.lastName = :lastName"),
    @NamedQuery(name = "Patient.findByPesel", query = "SELECT p FROM Patient p WHERE p.pesel = :pesel"),
    @NamedQuery(name = "Patient.findByDateOfBirth", query = "SELECT p FROM Patient p WHERE p.dateOfBirth = :dateOfBirth"),
    @NamedQuery(name = "Patient.findByPlaceOfBirth", query = "SELECT p FROM Patient p WHERE p.placeOfBirth = :placeOfBirth"),
    @NamedQuery(name = "Patient.findByStreet", query = "SELECT p FROM Patient p WHERE p.street = :street"),
    @NamedQuery(name = "Patient.findByCity", query = "SELECT p FROM Patient p WHERE p.city = :city"),
    @NamedQuery(name = "Patient.findByPost", query = "SELECT p FROM Patient p WHERE p.post = :post"),
    @NamedQuery(name = "Patient.findByPostCode", query = "SELECT p FROM Patient p WHERE p.postCode = :postCode"),
    @NamedQuery(name = "Patient.findByPhone", query = "SELECT p FROM Patient p WHERE p.phone = :phone"),
    @NamedQuery(name = "Patient.findByPaymentInstitution", query = "SELECT p FROM Patient p WHERE p.paymentInstitution = :paymentInstitution"),
    @NamedQuery(name = "Patient.findByEmail", query = "SELECT p FROM Patient p WHERE p.email = :email"),
    @NamedQuery(name = "Patient.findByInsuranceNumber", query = "SELECT p FROM Patient p WHERE p.insuranceNumber = :insuranceNumber"),
    @NamedQuery(name = "Patient.findByInsuranceType", query = "SELECT p FROM Patient p WHERE p.insuranceType = :insuranceType")})
public class Patient implements Serializable, IPatient {
    @Column(name =     "date_of_birth")
    @Temporal(TemporalType.DATE)
    private Date dateOfBirth;
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "patient_sequence_", sequenceName = "patient_sequence", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "patient_sequence_")
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Long id;
    @Size(max = 250)
    @Column(name = "first_name")
    private String firstName;
    @Size(max = 250)
    @Column(name = "last_name")
    private String lastName;
    @Size(max = 15)
    @Column(name = "pesel")
    private String pesel;
    @Size(max = 250)
    @Column(name = "place_of_birth")
    private String placeOfBirth;
    @Size(max = 250)
    @Column(name = "street")
    private String street;
    @Size(max = 250)
    @Column(name = "city")
    private String city;
    @Size(max = 250)
    @Column(name = "post")
    private String post;
    @Size(max = 6)
    @Column(name = "post_code")
    private String postCode;
    // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
    @Size(max = 250)
    @Column(name = "phone")
    private String phone;
    @Column(name = "payment_institution")
    private BigInteger paymentInstitution;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 250)
    @Column(name = "email")
    private String email;
    @Size(max = 250)
    @Column(name = "insurance_number")
    private String insuranceNumber;
    @Size(max = 10)
    @Column(name = "insurance_type")
    private String insuranceType;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "patient")
    private List<Referral> referralList;
    @OneToMany(mappedBy = "patient")
    private List<Visit> visitList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "patient")
    private List<Reservation> reservationList;

    public Patient() {
    }

    public Patient(Long id) {
        this.id = id;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getFirstName() {
        return firstName;
    }

    @Override
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Override
    public String getLastName() {
        return lastName;
    }

    @Override
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Override
    public String getPesel() {
        return pesel;
    }

    @Override
    public void setPesel(String pesel) {
        this.pesel = pesel;
    }

    @Override
    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    @Override
    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    @Override
    public String getPlaceOfBirth() {
        return placeOfBirth;
    }

    @Override
    public void setPlaceOfBirth(String placeOfBirth) {
        this.placeOfBirth = placeOfBirth;
    }

    @Override
    public String getStreet() {
        return street;
    }

    @Override
    public void setStreet(String street) {
        this.street = street;
    }

    @Override
    public String getCity() {
        return city;
    }

    @Override
    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String getPost() {
        return post;
    }

    @Override
    public void setPost(String post) {
        this.post = post;
    }

    @Override
    public String getPostCode() {
        return postCode;
    }

    @Override
    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    @Override
    public String getPhone() {
        return phone;
    }

    @Override
    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public BigInteger getPaymentInstitution() {
        return paymentInstitution;
    }

    @Override
    public void setPaymentInstitution(BigInteger paymentInstitution) {
        this.paymentInstitution = paymentInstitution;
    }

    @Override
    public String getEmail() {
        return email;
    }

    @Override
    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String getInsuranceNumber() {
        return insuranceNumber;
    }

    @Override
    public void setInsuranceNumber(String insuranceNumber) {
        this.insuranceNumber = insuranceNumber;
    }

    @Override
    public String getInsuranceType() {
        return insuranceType;
    }

    @Override
    public void setInsuranceType(String insuranceType) {
        this.insuranceType = insuranceType;
    }

    @XmlTransient
    @Override
    public List<Referral> getReferralList() {
        return referralList;
    }

    @Override
    public void setReferralList(List<Referral> referralList) {
        this.referralList = referralList;
    }

    @XmlTransient
    @Override
    public List<Visit> getVisitList() {
        return visitList;
    }

    @Override
    public void setVisitList(List<Visit> visitList) {
        this.visitList = visitList;
    }

    @XmlTransient
    @Override
    public List<Reservation> getReservationList() {
        return reservationList;
    }

    @Override
    public void setReservationList(List<Reservation> reservationList) {
        this.reservationList = reservationList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Patient)) {
            return false;
        }
        Patient other = (Patient) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.nazaweb.imedproplus.model.entity.Patient[ id=" + id + " ]";
    }

}
